<div class="modal-body pageContent">
    <div class="row">
        <div class="col-lg-12 col-md-12">
            
            <form action="/changePassword" enctype="multipart/form-data" method='post' id="changePwdForm">
                <div class="form-group">
                    <label class="col-lg-12 control-label">
                            <span class="indicator">*</span>
                            <span class="indicatorName">旧密码</span></label>
                    <div class="col-lg-12">
                        <input type="password" class="form-control" name="oldPassword" value="" />
                    </div>
                </div>
                <div class="form-group">
                        <label class="col-lg-12 control-label">
                                <span class="indicator">*</span>
                                <span class="indicatorName">新密码</span></label>
                        <div class="col-lg-12">
                            <input type="password" class="form-control" name="newPassword" value="" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-12 control-label">
                                <span class="indicator">*</span>
                                <span class="indicatorName">确认密码</span></label>
                        <div class="col-lg-12">
                            <input type="password" class="form-control" name="newPassword2" value="" />
                        </div>
                    </div>
                
            </form>
        </div>
    </div>
</div>
<div class="modal-footer pageFooter">
    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
    <button  class="btn btn-primary"  type="submit" >保存</button> 
</div>
<script>
    $(function(){
        $('#changePwdForm')
        .bootstrapValidator({
            live:'submitted',
            message: '此值无效',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                oldPassword: {
                    validators: {
                        notEmpty: {
                            message: '请填写旧密码'
                        }
                    }
                },
                newPassword: {
                    validators: {
                      notEmpty: {
                          message: '请填写新密码'
                        },
                        regexp: {
                            regexp: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9a-zA-Z]{8,}/,
                            message: '不能纯数字或纯字母,长度至少为8位'
                        }
                    }
                },
                newPassword2: {
                    validators: {
                        notEmpty: {
                        message: '请填写确认密码'
                        },
                        identical: {
                        field: 'newPassword',
                        message: '密码与确认密码不一致'
                        }
                    }
                }
            }
        })
        .on('success.form.bv', function(e) {
            // Prevent form submission
            e.preventDefault();
            // Get the form instance
            var $form = $(e.target);

            // Get the BootstrapValidator instance
            var bv = $form.data('bootstrapValidator');
            $.ajax({
                type: 'post',
                url:$form.attr('action'),
                data:$form.serialize(),
                success: function(result){
                    if(result.length===9371){   //session超时返回的登录页面 避免接口返回的也是字符串不是json
                                location.href="/severError";
                    }else{  //正常处理
                        // var resdata = result;
                        // var data = result.list[0];
                        // var getData= $("#productTable").bootstrapTable('getData');
                        if(result.statusCode =='200'){
                                location.href="/login";
                        }else{
                            toastr.warning(result.message+'!');
                        }
                    }
                },
                error: function (result) {       //后台数据异常返回503
                    if(result.status===503||result.status===500){ 
                        $('#changePassword').modal('hide');
                        toastr.error("服务端数据异常"+'!');
                    }
                } 
            })
        });
    })
</script>